using System;

namespace AntEater.ComponentModel
{
    /// <summary>
    /// An output class that fires event if line is written to the output.
    /// </summary>
    public class Output
    {
        /// <summary>
        /// Occurs if a line is written to the output
        /// </summary>
        public event EventHandler<OutputEventArgs> LineWritten;

        /// <summary>
        /// Occurs if the output should be cleared
        /// </summary>
        public event EventHandler<EventArgs> Cleared;

        /// <summary>
        /// Initializes a new instance of the <see cref="Output"/> class.
        /// </summary>
        public Output() {
        }

        /// <summary>
        /// Writes the line.
        /// </summary>
        /// <param name="value">The value.</param>
        public void WriteLine(string value) {

            // Fire line written event
            if (this.LineWritten != null) {
                this.LineWritten(this, new OutputEventArgs(value));
            }
        }

        /// <summary>
        /// Clears this instance.
        /// </summary>
        public void Clear() {

            // Fire cleared event
            if (this.Cleared != null) {
                this.Cleared(this, new EventArgs());
            }
        }
    }
}
